<template>
	<view>
		<view class="popbox u-p-30 u-radius-20">
			<view class="titlebox">
				<u-icon @click="close" name='arrow-left'></u-icon>
				<text>核对订单</text>
			</view>
			<scroll-view scroll-y="true" style="height: 600rpx;">
				<view class="" v-for="(item,index) in orderlist">
					<view class="u-font-bold u-m-t-40">快递信息</view>
					<view class="inputbox u-m-t-40">
						<text>位置：{{item.yztitle}}</text>
						<u-line margin='20rpx auto'></u-line>
					</view>
					<view class="inputbox u-m-t-40" v-if="ordertype==0">
						<text>取件码：{{item.pickupcode}}</text>
						<u-line margin='20rpx auto'></u-line>
					</view>
					<view class="inputbox u-m-t-40" v-if="ordertype==0">
						<text>快递单号：{{item.tracknumber}}</text>
						<u-line margin='20rpx auto'></u-line>
					</view>
					<view class="inputbox u-m-t-40" v-if="ordertype==1">
						<text>快递商家：{{item.business}}</text>
						<u-line margin='20rpx auto'></u-line>
					</view>
					<view class="inputbox u-m-t-40">
						<text>快递类型：{{item.type}}</text>
						<u-line margin='20rpx auto'></u-line>
					</view>
					<view class="inputbox u-m-t-40">
						<text>备注：{{item.remark}}</text>
						<u-line margin='20rpx auto'></u-line>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="settlement u-m-t-30 u-p-30">
			<view class="addess">
				<view class="" style="flex: 1;">
					<text class="u-m-r-20">{{info.Park}}</text>
					<text class="u-m-r-20">{{info.nickname}}</text>
					<text>{{info.mobile}}</text>
				</view>
				<text @click="showclick">更改地址</text>
			</view>
			<view class="price u-m-t-60">
				<view class="priceitem">
					<text class="u-font-bold">预估总价</text>
					<view style="color: red;">￥{{allprice}}({{allprice}}金币)</view>
				</view>
				<view class="wxpay u-font-26 u-p-lr-30 u-radius-20" @click="pay(1)">
					微信支付
				</view>
				<view class="coinpay  u-font-26  u-p-lr-30 u-radius-20" @click="pay(3)">
					金币支付
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "orderpop",
		props: {
			orderlist: {
				type: Array,
				default: []
			},
			ordertype: {
				type: Number,
				default: 0
			},
			allprice: {
				type: Number,
				default: 0.00
			}
		},
		data() {
			return {
				info: {},

			};
		},
		mounted() {
			this.init()
			uni.$on('changeinfo', () => {
				this.init()
			})

		},
		methods: {
			init() {
				this.$userinfo().then(res => {
					this.info = res.data.data
				}).catch(err => {
					console.log(err, '失败');
				})
			},
			showclick() {
				this.$emit('showclick', true)
				// this.show = false
			},
			close() {
				this.$emit('closeorder', false)
			},
			wxpayorder(ordersn, paytype) {
				this.$api.post('/Delivery/payorder', {
					ordersn,
					paytype,
					op: this.ordertype == 0 ? 1 : 2

				}).then(res => {
					this.$pay(res.data).then(res => {
						console.log(res, 'zxczxczxc');
						// if(res.errMsg!='requestPayment:fail cancel'){
						// 	this.$toast('下单成功~')
						// 	setTimeout(()=>{
						// 		uni.switchTab({
						// 			url:'/pages/index/index'
						// 		})
						// 	},1000)
						// }else{
						// 	this.$toast('取消支付~')
						// }
						this.$toast('下单成功~')
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/myallorder/myallorder?type=' + this.ordertype
							})
						}, 1000)
					}).catch(err => {
						console.log(err, 'err');
						this.$toast('取消支付~')
					})
				})
			},
			coinpayorder(ordersn, paytype) {
				this.$api.post('/Delivery/payorder', {
					ordersn,
					paytype,
					op: this.ordertype == 0 ? 1 : 2
				}).then(res => {
					if (res.code == 1) {
						this.$toast('下单成功~')
						setTimeout(() => {
							uni.redirectTo({
								url: '/pages/myallorder/myallorder?type=' + this.ordertype
							})
						}, 1000)
					}
				})
			},
			pay(type) {
				// console.log(this.orderlist);
				// return
				if(!this.info.Park){
					this.$toast('请先选择地址~');
					return
				}
				this.$api.post('/Delivery/Pickuppackage', {
					bejsarr: this.orderlist,
					op: this.ordertype == 0 ? 1 : 2

				}).then(res => {
					if (type == 1) {
						this.wxpayorder(res.data, 1)
					} else {
						this.coinpayorder(res.data, 3)
					}
				}).catch(err => {
					console.log(err);
				})
			},
		}
	}
</script>

<style lang="scss">
	.popbox {
		width: 686rpx;
		margin: 30rpx auto;
		background-color: #fff;
		box-sizing: border-box;

		.titlebox {
			width: 60%;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}

	.settlement {
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;

		.addess {

			display: flex;
			justify-content: space-between;
			color: grey;
		}

		.price {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.wxpay {
				background-color: rgb(103, 194, 58);
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
			}
			.coinpay{
				background-color: rgb(230, 162, 60);
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
			}
		}
	}
</style>